package financial.sharing.center.system.controller;

import financial.sharing.center.common.utils.R;
import financial.sharing.center.common.vo.Token;
import financial.sharing.center.system.service.SysAdminService;
import financial.sharing.center.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/4/22
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/system/login/")
public class LoginController {

    @Autowired
    private SysAdminService sysAdminServiceImpl;

    @Autowired
    private SysUserService sysUserServiceImpl;

    @PostMapping(value = "user/login")
    public R userLogin(@RequestParam(name = "username") String username,
                       @RequestParam(name = "password") String password,
                       @RequestParam(name = "role") String role){
        Token token = null;
        if ("admin".equals(role)){
            token = this.sysAdminServiceImpl.getToken(username, password);
        }else if ("user".equals(role)){
            token = this.sysUserServiceImpl.getToken(username, password);
        }
        return R.ok(token);
    }

}
